package com.puman.beautyfarmcounselor.ui.home;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.TextView;

import com.puman.beautyfarmcounselor.MainActivity;
import com.puman.beautyfarmcounselor.R;

/**
 */
//@EFragment(R.layout.fragment_web)
@SuppressLint("ValidFragment")
public class WebFragment extends Fragment implements View.OnClickListener {

    WebSettings webSettings;
    View view;

    TextView titleView;
    ImageView back;

    private String webUrl = "";
    private String title = "促销活动";

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_web, null);
        updateView();
        return view;
    }
    public WebFragment() {
    }


    public WebFragment(String title, String webUrl) {
        this.title = title;
        this.webUrl = webUrl;
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);

    }

    public void updateView() {
        titleView = (TextView) view.findViewById(R.id.base_title);
        titleView.setText(title);
        back = (ImageView) view.findViewById(R.id.back_btn);
        back.setVisibility(View.VISIBLE);
        back.setOnClickListener(this);


        MainActivity.getInstace().webView = (WebView) view.findViewById(R.id.webview);
        webSettings = MainActivity.getInstace().webView.getSettings();
        MainActivity.getInstace().webView.setWebViewClient(new WebViewClient());//all links the user clicks load in your WebView.
        webSettings.setJavaScriptEnabled(true);
        webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);//cash
        webSettings.setSupportZoom(true);
        webSettings.setDisplayZoomControls(true);

        Log.i("curry", "webUrl:" + webUrl);
        MainActivity.getInstace().webView.loadUrl(webUrl);

    }

    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.back_btn:
                MainActivity.getInstace().getSupportFragmentManager().popBackStack();
                break;
        }
    }

}
